package com.protocols.sctp;

import java.io.DataOutputStream;
import java.io.IOException;
import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.util.Arrays;
import java.util.logging.Logger;

import com.protocols.GeneralProtocolData;
import com.protocols.ProtoOperations;
import com.protocols.sctp.m3ua.M3uaHandlerInterface;

public class TreatInCommingTcp extends Thread {

	private byte [] input;
	private Logger Log;
	private DataOutputStream outToServer;
	private M3uaHandlerInterface M3uaHandler;
	private long SessionID=0;
	
	public TreatInCommingTcp(byte [] input, M3uaHandlerInterface m3uaHandler, DataOutputStream outToServer,  long sessionid) {
		this.input=input;
		this.M3uaHandler=m3uaHandler;
		this.outToServer=outToServer;
		
		SessionID=sessionid;
		
	}

    public void run()
    {    	
        // call the remote method
    	try {
    		GeneralProtocolData response=M3uaHandler.sctpToM3ua(SessionID,input);
    		
			if(response==null)
			{
			}
			else
			{
					outToServer.write(response.getByteArray());	/// if returned a response Write to Sctp Socket
					
			}
			
		} catch ( Exception e) {
			Log.warning(SessionID+":Exception Occured :" +e.getClass().getSimpleName()+":"+ Arrays.toString(e.getStackTrace()));
			
		}
    }
}
